﻿using System.Web.Services;
using RN.ERP.BLL;
using System.Text.RegularExpressions;
using Fly.FlyCommon;
using Newtonsoft.Json;

using BllType = RN.ERP.BLL.BllType;

namespace RN.ERP
{
    /// <summary>
    /// EnterpriseWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class EnterpriseWebService : System.Web.Services.WebService
    {
        private BasePersonBLL pbll = (BasePersonBLL)BllFactory.CreateBll(BllType.Person, Utilities.GetDbType());
        private BaseEnterpriseBLL enterpriseBll = (BaseEnterpriseBLL)BllFactory.CreateBll(BllType.Enterprise, Utilities.GetDbType());
        private BaseBasicBLL basicBll = (BaseBasicBLL)BllFactory.CreateBll(BllType.Basic, Utilities.GetDbType());

        #region 企业服务

        [WebMethod]
        public string GetCorpQualities(string corpUserGuid)
        {
            //BaseEnterpriseBLL enterpriseBll = (BaseEnterpriseBLL)BllFactory.CreateBll(BllType.Enterprise, areaCode);
            Regex reg = new Regex("\"(\\w+)\"(\\s*:\\s*)");
            string json = enterpriseBll.GetCorpQualities(corpUserGuid, string.Empty);
            string json1 = reg.Replace(json, "$1$2");

            return json1;
        }

        [WebMethod(Description = "招标代理单位能否担任此活。")]
        public string CheckCorpQuality(string dogId, string objStr)
        {
            //BaseEnterpriseBLL enterpriseBll = (BaseEnterpriseBLL)BllFactory.CreateBll(BllType.Enterprise, areaCode);
            return JsonConvert.SerializeObject(enterpriseBll.CheckCorpQuality(dogId, objStr, string.Empty));
        }

        [WebMethod(Description = "根据省库KeyID获取青岛企业信息。")]
        public string GetCorpInfoForDL(string dogID)
        {
            // BaseEnterpriseBLL enterpriseBll = (BaseEnterpriseBLL)BllFactory.CreateBll(BllType.Enterprise, areaCode);
            return enterpriseBll.GetCorpInfoForDL(dogID, string.Empty);
        }
        #endregion
        #region 人员服务

        #region 人员押证查询

        /// <summary>
        /// 人员押证查询
        /// </summary>
        /// <param name="empId"></param>
        /// <returns></returns>
        [WebMethod(Description = "获取项目负责人状态。")]
        public string CheckXMFZR(string EmpId)
        {
            //BasePersonBLL pbll = (BasePersonBLL)BllFactory.CreateBll(BllType.Person, Utilities.GetDbType());
            return pbll.CheckXMFZR(EmpId);
        }
        [WebMethod(Description = "获取项目负责人状态。")]
        public string CheckPersonXMFZR(string empId, string roleId, string areaCode)
        {
            //BasePersonBLL pbll = (BasePersonBLL)BllFactory.CreateBll(BllType.Person, areaCode);
            return pbll.CheckXMFZR(empId, roleId, areaCode);
        }
        #endregion

        [WebMethod(Description = "是否是项目主管。")]
        public bool CheckEmp(string empguid, string areaCode)
        {
            //BasePersonBLL pbll = (BasePersonBLL)BllFactory.CreateBll(BllType.Person, areaCode);
            return pbll.CheckEmp(empguid, areaCode);
        }

        [WebMethod(Description = "获取人员及资质信息。")]
        public string GetManagerInfoForDL(string DogID, string areaCode)
        {
            //BasePersonBLL pbll = (BasePersonBLL)BllFactory.CreateBll(BllType.Person, areaCode);
            return JsonConvert.SerializeObject(pbll.GetManagerInfoForDL(DogID, areaCode));
        }

        #endregion

        [WebMethod]
        public string GetQualitiesDic(string rootCode, string parentId)
        {
            //BaseBasicBLL basicBll = (BaseBasicBLL)BllFactory.CreateBll(BllType.Basic, string.Empty);
            Regex reg = new Regex("\"(\\w+)\"(\\s*:\\s*)");
            string json = JsonConvert.SerializeObject(basicBll.GetQualitiesDic(rootCode, parentId));
            string json1 = reg.Replace(json, "$1$2");
            return json1;
        }

        [WebMethod]
        public string GetManagerByZbdlDogid(int dogid)
        {
            //BasePersonBLL pbll = (BasePersonBLL)BllFactory.CreateBll(BllType.Person, string.Empty);
            return pbll.GetManagerByZbdlDogid(dogid);
        }

        [WebMethod]
        public string GetCompanyinfoByZbdlDogid(int dogid)
        {
            //BaseEnterpriseBLL enterpriseBll = (BaseEnterpriseBLL)BllFactory.CreateBll(BllType.Enterprise, string.Empty);
            return enterpriseBll.GetCompanyinfoByZbdlDogid(dogid);
        }
    }
}

